﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MvcCarConsume.WebUI
{
    public class VMLanguageMenuItem
    {
        public string CultureString { get; set; }
        public string DisplayName { get; set; }
        public string Url { get; set; }
    }

    public class VMLanguageMenu
    {
        public VMLanguageMenuItem currentLang { get; set; }
        public List<VMLanguageMenuItem> Langs { get; set; }
        public VMLanguageMenu()
        {
            currentLang = new VMLanguageMenuItem();
            Langs = new List<VMLanguageMenuItem>();

            Langs.Add(new VMLanguageMenuItem { 
                CultureString = "en-us",
                DisplayName = "United States (English)"
            });
            Langs.Add(new VMLanguageMenuItem
            {
                CultureString = "zh-cn",
                DisplayName = "中国 (简体中文)"
            });
        }

        public void InitMenu(string currentUrl , string cultureString)
        {
            string pattern = currentUrl.Replace(cultureString,"{0}");
            foreach (var l in Langs)
            {
                if (cultureString == l.CultureString)
                    currentLang = l;
                l.Url = string.Format(pattern, l.CultureString);
            }
        }
    }


}